package com.niodata.dp.core.dblock;

/**
 * A simple lock based on database. Usage: DbLock lock=new DbLockImpl(); try{ lock.tryLock();
 * }finally{ lock.releaseLock(); }
 */
public interface DbLock {

  /**
   * try to lock on lockname.
   *
   * @param lockName lockname
   * @param timeout timeout seconds
   */
  void tryLock(String lockName, int timeout);

  /**
   * try to lock on lockname.
   *
   * @param lockName lockname
   */
  void tryLock(String lockName);

  /**
   * release current thread holed lock.
   *
   * @param lockName lockname
   */
  void releaseLock(String lockName);

  /**
   * get lock info,return null if not exists.
   *
   * @param lockName lockname
   * @return lock
   */
  Lock getLock(String lockName);
}
